package agent_store

import (
	"context"
	"github.com/spf13/cast"
	"xialou_platform/services/agent/rpc/agent"

	"xialou_platform/services/agent/api/internal/svc"
	"xialou_platform/services/agent/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoreExistLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewStoreExistLogic(ctx context.Context, svcCtx *svc.ServiceContext) StoreExistLogic {
	return StoreExistLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *StoreExistLogic) StoreExist(req *types.StoreExistReq) (resp *types.StoreExistResp, err error) {
	resp = &types.StoreExistResp{
		IsExist: false,
	}
	existResp, err := l.svcCtx.AgentRpc.StoreCheckExist(l.ctx, &agent.StoreCheckExistReq{
		StoreId:  cast.ToInt64(req.StoreId),
		Platform: req.Platform,
	})
	if err != nil {
		logx.Error("StoreExist err: ", err)
		return resp, nil
	}
	resp.IsExist = existResp.Exist
	return resp, err
}
